/**
 * 各种验证
 */

//用户登录验证
function userCheck(){
	var username=document.getElementById("username").value;
	var password=document.getElementById("password").value;
	var code=document.getElementById("code").value;
	var isUsername=/([0-9]|[a-z]|[A-Z]){6,16}/;
	var isPassword=/.{6,20}/;
	var isCode=/([0-9]|[a-z]|[A-Z]){4}/;
	if(!isCode.test(code)){
		window.alert("验证码不正确");
		return false;
	}
	if(!isUsername.test(username)){
		window.alert("用户名长度不正确,或者输入了非字母、数字");
		return false;
	}
	if(!isPassword.test(password)){
		window.alert("密码长度不正确，或输入了不允许的字符");
		return false;
	}
	
}

//用户注册验证
function registerCheck(){
	var username=document.getElementById("username").value;
	var password1=document.getElementById("password1").value;
	var password2=document.getElementById("password2").value;
	var name=document.getElementById("name").value;
	var email=document.getElementById("email").value;
	var tel=document.getElementById("tel").value;
	var code=document.getElementById("code").value;
	
	var isUsername=/([0-9]|[a-z]|[A-Z]){6,16}/;
	var isPassword=/.{6,20}/;
	var isName=/.{2,40}/;
	var isEmail=/.{5,60}/;
	var isTel=/[0-9]{11}/;
	var isCode=/([0-9]|[a-z]|[A-Z]){4}/;
	
	if(!isCode.test(code)){
		window.alert("验证码不正确");
		return false;
	}
	if(!isUsername.test(username)){
		window.alert("用户名长度不正确,或者输入了非字母、数字");
		return false;
	}
	if(!isPassword.test(password1)){
		window.alert("密码长度不正确，或输入了不允许的字符");
		return false;
	}
	if(password1!=password2){
		window.alert("两次输入的密码不一致");
		return false;
	}
	if(!isName.test(name)){
		window.alert("姓名不符合要求");
		return false;
	}
	if(!isEmail.test(email)){
		window.alert("email格式不正确");
		return false;
	}
	if(!isTel.test(tel)){
		window.alert("电话长度必须是11位");
		return false;
	}
}

//发表留言验证
function wordCheck(){
	var name=document.getElementById("name").value;
	var email=document.getElementById("email").value;
	var tel=document.getElementById("tel").value;
	var code=document.getElementById("code").value;
	var info=document.getElementById("info").value;
	
	var isName=/.{2,40}/;
	var isEmail=/.{5,60}/;
	var isTel=/[0-9]{11}/;
	var isCode=/([0-9]|[a-z]|[A-Z]){4}/;
	var isInfo=/.{1,80}/;
	
	if(!isCode.test(code)){
		window.alert("验证码不正确");
		return false;
	}
	if(!isName.test(name)){
		window.alert("姓名不符合要求");
		return false;
	}
	if(!isEmail.test(email)){
		window.alert("email格式不正确");
		return false;
	}
	if(!isTel.test(tel)){
		window.alert("电话长度必须是11位");
		return false;
	}
	if(!isInfo.test(info)){
		window.alert("留言内容限制80个字符以内");
		return false;
	}
}

//发布兼职信息验证
function jobCheck(){
	var title=document.getElementById("title").value;
	var info=document.getElementById("info").value;
	var upload=document.getElementById("upload").files[0];
	var code=document.getElementById("code").value;
	
	
	var isTitle=/.{3,20}/;
	var isInfo=/.{5,9000}/;
	var isUpload=/.+\.(jpg|JPG)/;
	var isCode=/([0-9]|[a-z]|[A-Z]){4}/;
	
	
	if(!isCode.test(code)){
		window.alert("验证码不正确");
		return false;
	}
	if(!isTitle.test(title)){
		window.alert("标题必须3-20个字符");
		return false;
	}
	if(info.length>9000 || info.length<5){
		window.alert("内容必须5-9000个字符,现在"+info.length+"字符，花哨的样式会占用大量的字符");
		return false;
	}
	if(!isUpload.test(upload.name)){
		window.alert("图片格式必须是jpg");
		return false;
	}
	if((upload.size/1024/1024)>1){
		window.alert("图片大小必须是1MB以内");
		return false;
	}
}
